/*
  ASCII table
 
 Prints out byte values in all possible formats:  
 * as raw binary values
 * as ASCII-encoded decimal, hex, octal, and binary values
 
 For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
 
 The circuit:  No external hardware needed.
 
 created 2006
 by Nicholas Zambetti 
 modified 18 Jan 2009
 by Tom Igoe
 
 This example code is in the public domain.

 <http://www.zambetti.com> 
 
 */
int thisArray[15][3] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,
                        37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
                        52,53,02,03,04,05,06,07, 8, 9,10,11,12,13,21};
int nowValue=50;

void setup() 
{ 
  int thisByte = 33; 
  Serial.begin(9600); 
  // prints title with ending line break 
  Serial.println("ASCII Table ~ Character Map"); 
  blackOut(); 
}

// first visible ASCIIcharacter '!' is number 33:
// you can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!';  

void loop() 
{
  for (int i=0;i<6;i++)
  crossColor(i);
}


void blackOut()
{
  for (int i=0;i<15;i++){
    for(int j=0;j<3;j++){
      digitalWrite(thisArray[i][j],HIGH);
      pinMode(thisArray[i][j],OUTPUT);
    }
  }
}
void chaseAllLed(int lOrR,int timems)
{
  if(lOrR){
    
    for (int i=0;i<15;i++){
      for(int j=0;j<3;j++){
        digitalWrite(thisArray[i][j],LOW);
        delay(timems);
        digitalWrite(thisArray[i][j],HIGH);
      }
    }
  }
  else {
    for (int i=14;i>=0;i--){
      for(int j=2;j>=0;j--){
        digitalWrite(thisArray[i][j],LOW);
        delay(timems);
        digitalWrite(thisArray[i][j],HIGH);
      }
    }
  }
}
void chaseColorLed(int colorLed)
{
  for (int i=0;i<15;i++){
      digitalWrite(thisArray[i][colorLed],LOW);
      delay(50);
      digitalWrite(thisArray[i][colorLed],HIGH);
  }
  for (int i=14;i>=0;i--){
      digitalWrite(thisArray[i][colorLed],LOW);
      delay(50);
      digitalWrite(thisArray[i][colorLed],HIGH);
  }
}
void allColorLed(int colorLed)
{
  if (colorLed<3){
    for (int i=0;i<15;i++){
      digitalWrite(thisArray[i][colorLed],LOW);
      //digitalWrite(thisArray[i][colorLed],HIGH);
    }
  }
  else {
    for (int i=0;i<15;i++){
      for(int j=0;j<3;j++){
        digitalWrite(thisArray[i][j],LOW);
      }
    }
  }
}



void levelLed(int lOrR,int levelOfLedTemp, int colorLed)
{ 
  int nbLed=0;
  int levelOfLed=levelOfLedTemp*45/100;
  blackOut();
  if(lOrR){
    for (int i=0;i<15;i++){
      for(int j=0;j<3;j++){
        if((j==colorLed || colorLed>2)&&nbLed<levelOfLed){
          digitalWrite(thisArray[i][j],LOW);
        }
        nbLed++;
      }
    }
  }
  else {
    for (int i=14;i>=0;i--){
      for(int j=2;j>=0;j--){
        if((j==colorLed || colorLed>2)&&nbLed<levelOfLed){
          digitalWrite(thisArray[i][j],LOW);
        }
        nbLed++;
      }
    }
  }
}

void crossColor(int mode)
{
  int color1;
  int color2;
  if (mode==0){
    color1=0;
    color2=1;
  }
  if (mode==1){
    color1=1;
    color2=2;
  }
  if (mode==2){
    color1=2;
    color2=0;
  }
  if (mode==3){
    color1=2;
    color2=1;
  }
  if (mode==4){
    color1=1;
    color2=0;
  }
  if (mode==5){
    color1=0;
    color2=1;
  }
  if (mode==6){
    color1=0;
    color2=1;
  }
  blackOut();
  for (int i=0;i<15;i++)
  {
    blackOut();
    digitalWrite(thisArray[i][color1],LOW);
    digitalWrite(thisArray[15-i][color2],LOW);
    delay(50);
  }
}

